﻿using System;
using Microsoft.Practices.ObjectBuilder;
using CMSWCSFSolution.CMS.Views;
using CMS.Channel;
using CMS.Model;
using System.Collections.Generic;
using CMSWCSFSolution.CMS;
using System.Web.UI.WebControls;
using CMS.Logging;

namespace CMSWCSFSolution.CMS.Views
{
	public partial class CreateStudent : BasePage, ICreateStudentView
    {
        #region Ptotected Method
        private CreateStudentPresenter _presenter;
        [CreateNew]
        public CreateStudentPresenter Presenter
        {
            get
            {
                return this._presenter;
            }
            set
            {
                if (value == null)
                    throw new ArgumentNullException("value");

                this._presenter = value;
                this._presenter.View = this;
            }
        }
        /// <summary>
        /// Handles the Load event of the Page control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
		protected void Page_Load(object sender, EventArgs e)
		{
			if (!this.IsPostBack)
            {
                
                try 
                {
                _presenter.OnSelectedAllGrades();
                }
                catch (Exception ee)
                {
                    Logging.LogWrite(ee.Message.ToString(), Logging.Category.Error, Logging.Priority.Highest);
                }
			}
		}
        /// <summary>
        /// Handles the Click event of the BtnSave control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        protected void BtnSave_Click(object sender, EventArgs e)
        {
            try
            {
                _presenter.OnAddStudent();
                ShowMessage(1,"Create");
                
            }
            catch (Exception ee)
            {
                Logging.LogWrite(ee.Message.ToString(), Logging.Category.Error, Logging.Priority.High);
                ShowMessage(3,"error");
            }
        }
        #endregion

        #region Public Property
        /// <summary>
        /// Sets the bind class.
        /// </summary>
        /// <value>
        /// The bind class.
        /// </value>
        public List<Grade> BindClass
        {
            set
            {
                ddlClassName.DataSource = value;
                ddlClassName.DataValueField = "ClassID";
                ddlClassName.DataTextField = "ClassName";
                ddlClassName.DataBind();
                this.ddlClassName.Items.Insert(0, "Please Select");
                this.ddlClassName.SelectedIndex = 0;
            }
        }
        /// <summary>
        /// Gets the student insert.
        /// </summary
        public Student studentInsert
        {
            get
            {
                Grade grade = new Grade();
                Student student = new Student(grade);
                student.StudentName = txtStudentName.Text.Trim();
                student.StudentGender = (RadioBtnFemale.Checked == true) ? RadioBtnFemale.Text.Trim() : RadioBtnMale.Text.Trim();
                student.Grade.ClassId = int.Parse(ddlClassName.SelectedValue.ToString());
                return student;
            }
        }
        #endregion
    }
}

